<!DOCTYPE html>
<html>
<head>@ include("/weixin/include/header.html",{"title":"发起流程"}){}
</head>
<body>
	<form id="form1" method="post" action="${basePath}/weixinFlow/doSend" enctype="multipart/form-data"> <input
			type="hidden" name="targetId" id="targetId" value="">
		<div class="weui_cells weui_cells_form" style="margin-top: 14px;">
			<div class="weui_cell">
				<div class="weui_cell_bd weui_cell_primary">
					<input class="weui_input" type="tel" name="title"
						placeholder="请输入流程标题">
				</div>
			</div>
		</div>
		<div class="weui_cells weui_cells_form" style="margin-top: 14px;">
			<div class="weui_cell" style="margin-top: 14px;">
				<div class="weui_cell_bd weui_cell_primary">
					<textarea class="weui_textarea" placeholder="请输入流程说明" rows="4"
						name="content"></textarea>
				</div>
			</div>
		</div>
	<div class="attaches "><a class="btn_add_attach align_center" onclick="addAttach()">添加附件</a>
		<div id="file_container" class="attach_item h_align_center"></div>
		<div class="attach_item h_align_center" id="img_container">
		</div>
		<div class="v_dir" id="wxfile_view_container">
			
		
		</div>
		
	</div>
<input type="file"  multiple="true" name="attach" onchange="onChange()" id="attach_file" style="display: none;">
<input type="hidden" name="serverId" id="serverId">
<input type="hidden" name="wxFileId" id="wxFileId">
	</form>
	<div class="tree" style="margin-top: 14px" id="tree"></div>

	
<div id="file_list" class='weui-popup-container file_container'>
	<div class="wxfile_container_inner v_dir">
		<div id="wxfile_container">
		@  for(file in fileList){
			<a onclick="checkFile(this)">
				<div class="file_item h_align_center" id="wx_${file.attach_id}">
					<i></i>
					<div class="file_thumb align_center">
						<img src="${basePath}${file.thumb_url}">
					</div>
					
					<div class="align_center file_des">
						<span>上传时间：${file.ctime,"yyyy-MM-dd HH:mm"}</span>
					</div>
				</div>
			</a>
		@  }
			
		</div>
		
			<script type="text/javascript">
				var wxFileData =  [
					@  for(file in fileList){
						{"id":"${file.attach_id}","name":"${file.name}"},
					@  }
		];
			</script>
			<a id="btn_wxfile_close" onclick="closePopup()"class="weui_btn weui_btn_primary" style="margin: 16px;">关闭</a>
		</div>
    </div>


	<a href="javascript:submit();" class="weui_btn weui_btn_primary"
		style="margin: 16px;">发起流程</a>
@	include("/weixin/include/js_import.html"){}
	<script type="text/javascript">
	var nodeData = [
					
@  for(node in nodeList){
					{"id":"${node.id}","name":"${node.name}","pid":["${node.pid}"],"type":"${node.type}"},
@  }
		];
	
		
		function aClick(icon,e){
			if(e != undefined){
				e.stopPropagation();
			}			
			$(".item.active").removeClass("active");
			
			var item = $(icon).parent();
			item.addClass("active");
			
		}
		
		function checkSubs(itemDiv, isChecked){
			if(isChecked){
				itemDiv.siblings().find(".item").addClass("active");
			}else{
				itemDiv.siblings().find(".item").removeClass("active");				
			}
		}
		
		
		function rowClick(div,e){
			e.stopPropagation();
			$(div).siblings().toggle();
		}
		
		function initNodes(){
			var tree = $("#tree");
			for(var i in nodeData){
				var item = nodeData[i];
				if(item.type == 't'){
					tree.append("<div class='row' id='"+item.type+"_"+item.id+"'><div class='item tea' data='"+item.id+"'  onclick='rowClick(this,event)'><a onclick='aClick(this,event)'></a><span>"+item.name+"</span></div></div>");
				
				}else if(item.type=="d1"){
					tree.append("<div class='row' id='"+item.type+"_"+item.id+"'><div class='item'  onclick='rowClick(this,event)'><span>"+item.name+"</span></div></div>");
							
				}			
			}
			
			for(var i in nodeData){
				var item = nodeData[i];
				var pidArray =(""+item.pid).split(",");
				for(var j in pidArray){
					moveTo(item.id,item.type,pidArray[j]);
				}
			}			
		}
		
		function submit(){
			var str = getSelectedIds();
			if(str == ""||str==null){
				alert("请选择下一环节的协办人");
			}else{
				if(imgId==""){
					form1.submit();
				}else{
					//form1.submit();
					$.showLoading("正在上传...");
					wx.uploadImage({
			            localId: imgId, // 需要上传的图片的本地ID，由chooseImage接口获得
			            isShowProgressTips: 0, // 默认为1，显示进度提示
			            success: function (res) {
			                var serverId = res.serverId; // 返回图片的服务器端ID
			               $("#serverId").val(serverId);
							form1.submit();
			            },
			            fail:function(res){
		          			$.hideLoading();
		          			$.alert("上传失败");
			            }
			        });
				}
				
			}
		}
		
		function getSelectedIds(){
			var id = $(".tea.active").first().attr("data");
			$("#targetId").val(id);
			var wxFileIds = "";
			$(".file_item.active").each(function(){
				var index = $(this).parent().index();
				wxFileIds = wxFileIds+wxFileData[index].id+",";
			});
			$("#wxFileId").val(wxFileIds);
			
			return id;
		}
		
		function moveTo(id,type,pid){
			pid = "d1_"+pid;
			if($("#"+pid)){
				if($("#"+type+"_"+id).parent().attr("id")=="tree"){
					$("#"+type+"_"+id).appendTo($("#"+pid));
				}else{
					$("#"+type+"_"+id).clone().appendTo($("#"+pid));
				}
			}
		}
	jQuery(document).ready(function($) {
		wx.config({
		    debug: false, 
		    appId: '${appId}', 
		    timestamp: ${timestamp}, 
		    nonceStr: '${nonceStr}',
		    signature: '${signature}',
		    jsApiList: [
		                'chooseImage',
		                'previewImage',
		                'uploadImage'
		                ] // 必填，需要使用的JS接口列表，所有JS接口列表见附录2
		});
		//${ori}
		wx.error(function(res){
			
		});
		initNodes();
		
	});
	
	</script>
</body>
</html>